package org.jivesoftware.smack;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.packet.RosterPacket.Item;
import org.jivesoftware.smack.util.StringUtils;

public class RosterGroup
{
  private String name;
  private Connection connection;
  private final List<RosterEntry> entries;

  RosterGroup(String paramString, Connection paramConnection)
  {
    this.name = paramString;
    this.connection = paramConnection;
    this.entries = new ArrayList();
  }

  public String getName()
  {
    return this.name;
  }

  public void setName(String paramString)
  {
    synchronized (this.entries)
    {
      Iterator localIterator = this.entries.iterator();
      while (localIterator.hasNext())
      {
        RosterEntry localRosterEntry = (RosterEntry)localIterator.next();
        RosterPacket localRosterPacket = new RosterPacket();
        localRosterPacket.setType(IQ.Type.SET);
        RosterPacket.Item localItem = RosterEntry.toRosterItem(localRosterEntry);
        localItem.removeGroupName(this.name);
        localItem.addGroupName(paramString);
        localRosterPacket.addRosterItem(localItem);
        this.connection.sendPacket(localRosterPacket);
      }
    }
  }

  public int getEntryCount()
  {
    synchronized (this.entries)
    {
      return this.entries.size();
    }
  }

  public Collection<RosterEntry> getEntries()
  {
    synchronized (this.entries)
    {
      return Collections.unmodifiableList(new ArrayList(this.entries));
    }
  }

  public RosterEntry getEntry(String paramString)
  {
    if (paramString == null)
      return null;
    paramString = StringUtils.parseBareAddress(paramString);
    String str = paramString.toLowerCase();
    synchronized (this.entries)
    {
      Iterator localIterator = this.entries.iterator();
      while (localIterator.hasNext())
      {
        RosterEntry localRosterEntry = (RosterEntry)localIterator.next();
        if (localRosterEntry.getUser().equals(str))
          return localRosterEntry;
      }
    }
    return null;
  }

  public boolean contains(RosterEntry paramRosterEntry)
  {
    synchronized (this.entries)
    {
      return this.entries.contains(paramRosterEntry);
    }
  }

  public boolean contains(String paramString)
  {
    return getEntry(paramString) != null;
  }

  public void addEntry(RosterEntry paramRosterEntry)
    throws XMPPException
  {
    PacketCollector localPacketCollector = null;
    synchronized (this.entries)
    {
      if (!this.entries.contains(paramRosterEntry))
      {
        RosterPacket localRosterPacket = new RosterPacket();
        localRosterPacket.setType(IQ.Type.SET);
        RosterPacket.Item localItem = RosterEntry.toRosterItem(paramRosterEntry);
        localItem.addGroupName(getName());
        localRosterPacket.addRosterItem(localItem);
        localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localRosterPacket.getPacketID()));
        this.connection.sendPacket(localRosterPacket);
      }
    }
    if (localPacketCollector != null)
    {
      ??? = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
      localPacketCollector.cancel();
      if (??? == null)
        throw new XMPPException("No response from the server.");
      if (((IQ)???).getType() == IQ.Type.ERROR)
        throw new XMPPException(((IQ)???).getError());
    }
  }

  public void removeEntry(RosterEntry paramRosterEntry)
    throws XMPPException
  {
    PacketCollector localPacketCollector = null;
    synchronized (this.entries)
    {
      if (this.entries.contains(paramRosterEntry))
      {
        RosterPacket localRosterPacket = new RosterPacket();
        localRosterPacket.setType(IQ.Type.SET);
        RosterPacket.Item localItem = RosterEntry.toRosterItem(paramRosterEntry);
        localItem.removeGroupName(getName());
        localRosterPacket.addRosterItem(localItem);
        localPacketCollector = this.connection.createPacketCollector(new PacketIDFilter(localRosterPacket.getPacketID()));
        this.connection.sendPacket(localRosterPacket);
      }
    }
    if (localPacketCollector != null)
    {
      ??? = (IQ)localPacketCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
      localPacketCollector.cancel();
      if (??? == null)
        throw new XMPPException("No response from the server.");
      if (((IQ)???).getType() == IQ.Type.ERROR)
        throw new XMPPException(((IQ)???).getError());
    }
  }

  public void addEntryLocal(RosterEntry paramRosterEntry)
  {
    synchronized (this.entries)
    {
      this.entries.remove(paramRosterEntry);
      this.entries.add(paramRosterEntry);
    }
  }

  void removeEntryLocal(RosterEntry paramRosterEntry)
  {
    synchronized (this.entries)
    {
      if (this.entries.contains(paramRosterEntry))
        this.entries.remove(paramRosterEntry);
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     org.jivesoftware.smack.RosterGroup
 * JD-Core Version:    0.6.1
 */